package com.ws.service.impl;

import com.github.pagehelper.Page;
import com.ws.common.CommonConstant;
import com.ws.common.PaasPage;
import com.ws.entity.Feedback;
import com.ws.repository.FeedbackRepository;
import com.ws.service.FeedbackService;
import com.ws.util.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author ：ws
 * @date ：Created in 2023/10/24 10:49
 * @description：TODO
 * @modified By：
 * @version: 1.0.0
 */
@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    FeedbackRepository feedbackRepository;

    @Override
    public PaasPage<Feedback> getFeedbackPage(Pageable pageable, Long readerId,String statusCd) {
        PageUtil.setPageAndOrderBy(pageable);
        Feedback feedback = new Feedback();
        feedback.setReaderId(readerId);
        if(StringUtils.isEmpty(statusCd)){
            statusCd = CommonConstant.ADD_STATUS_CD;
        }
        feedback.setStatusCd(statusCd);
        Page<Feedback> feedbackPage = feedbackRepository.getFeedbackPage(feedback);
        return PageUtil.transformPage(feedbackPage);
    }

    @Override
    public Feedback saveFeedback(Feedback feedback) {
        feedback.setStatusCd(CommonConstant.ADD_STATUS_CD);
        feedback.setCreateTime(new Date());
        feedbackRepository.saveFeedback(feedback);
        return feedback;
    }

    @Override
    public Feedback getFeedbackBasicInfo(Long feedbackId) {
        return feedbackRepository.getFeedbackBasicInfo(feedbackId);
    }

    @Override
    public void delFeedback(Long feedbackId) {
        feedbackRepository.delFeedback(feedbackId);
    }

    @Override
    public Feedback updateFeedback(Long feedbackId, Feedback feedback) {
        feedbackRepository.updateFeedback(feedback);
        return feedback;
    }
}
